from django import template

register = template.Library()

@register.filter(name='rank')
def rank(value,list):
    return list.index(value)+1

@register.filter(name='formatedscore')
def formatedscore(value, decimal_points=3, seperator=u'.'):
    if value != None:
        value = str(value)
        if len(value) <= decimal_points:
            return value
        # say here we have value = '12345' and the default params above
        parts = []
        while value:
            parts.append(value[-decimal_points:])
            value = value[:-decimal_points]
        # now we should have parts = ['345', '12']
        parts.reverse()
        # and the return value should be u'12.345'
        return seperator.join(parts)
    else :
        return "-"
